#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define lld long long
#define ENDL '\n'
#define LOG(var) std::cout << #var << " = " << (var) << ENDL
using std::cin;
using std::cout;
using std::string;
using std::vector;
void solve() {
  // body
  int n, m;
  cin >> n >> m;
  vector<lld> s(n + 1), t(m + 1);
  vector<lld> PreS(n + 1), PreT(m + 1);
  for (int i = 1; i <= n; ++i)
    cin >> s[i];
  for (int i = 1; i <= m; ++i)
    cin >> t[i];
  std::sort(t.begin() + 1, t.begin() + 1 + m);

  PreS[0] = 0;
  for (int i = 1; i <= n; ++i) {
    PreS[i] = PreS[i - 1] + s[i];
    // LOG(PreS[i]);
  }
  PreT[0] = 0;
  for (int i = 1; i <= m; ++i) {
    PreT[i] = PreT[i - 1] + t[i];
    // LOG(PreT[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    lld x = -PreS[i] - 1;
    // 第一个比 x 大的数字
    auto it = upper_bound(PreT.begin(), PreT.begin() + 1 + m, x);
    // -1 找到比他小的数字 使用了前 j 个 B 的元素
    // 可以一个都不选
    int j = (it - PreT.begin()) - 1;
    if (j >= 0 && (PreS[i] + PreT[j]) < 0)
      ans = std::max(ans, i + j);
  }
  cout << ans << ENDL;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}

/*
input
3
3 2
1 2 3
1 2
3 2
1 2 3
-1 -2
3 3
-4 3 1
4 2 1

output
0
3
3
*/